from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-25 14:03:20.680980
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 25, Aug, 2022
Time: 14:03:26
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.2021
Nobs: 759.000 HQIC: -50.5398
Log likelihood: 9657.36 FPE: 9.09886e-23
AIC: -50.7513 Det(Omega_mle): 8.08772e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298428 0.055023 5.424 0.000
L1.Burgenland 0.106330 0.036549 2.909 0.004
L1.Kärnten -0.106432 0.019407 -5.484 0.000
L1.Niederösterreich 0.206395 0.076313 2.705 0.007
L1.Oberösterreich 0.111666 0.074035 1.508 0.131
L1.Salzburg 0.252953 0.039081 6.473 0.000
L1.Steiermark 0.036835 0.050995 0.722 0.470
L1.Tirol 0.106489 0.041277 2.580 0.010
L1.Vorarlberg -0.059866 0.035489 -1.687 0.092
L1.Wien 0.051941 0.065913 0.788 0.431
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.062384 0.114357 0.546 0.585
L1.Burgenland -0.034280 0.075962 -0.451 0.652
L1.Kärnten 0.047135 0.040334 1.169 0.243
L1.Niederösterreich -0.174211 0.158605 -1.098 0.272
L1.Oberösterreich 0.397152 0.153871 2.581 0.010
L1.Salzburg 0.289484 0.081224 3.564 0.000
L1.Steiermark 0.104464 0.105985 0.986 0.324
L1.Tirol 0.314638 0.085789 3.668 0.000
L1.Vorarlberg 0.026518 0.073759 0.360 0.719
L1.Wien -0.025824 0.136991 -0.189 0.850
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190319 0.028301 6.725 0.000
L1.Burgenland 0.089004 0.018799 4.734 0.000
L1.Kärnten -0.008590 0.009982 -0.861 0.389
L1.Niederösterreich 0.259660 0.039251 6.615 0.000
L1.Oberösterreich 0.134935 0.038080 3.544 0.000
L1.Salzburg 0.045730 0.020101 2.275 0.023
L1.Steiermark 0.017446 0.026229 0.665 0.506
L1.Tirol 0.093331 0.021231 4.396 0.000
L1.Vorarlberg 0.058638 0.018254 3.212 0.001
L1.Wien 0.120588 0.033902 3.557 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.106571 0.028729 3.710 0.000
L1.Burgenland 0.046683 0.019083 2.446 0.014
L1.Kärnten -0.014485 0.010133 -1.429 0.153
L1.Niederösterreich 0.192778 0.039845 4.838 0.000
L1.Oberösterreich 0.289863 0.038656 7.499 0.000
L1.Salzburg 0.111990 0.020405 5.488 0.000
L1.Steiermark 0.102216 0.026626 3.839 0.000
L1.Tirol 0.109763 0.021552 5.093 0.000
L1.Vorarlberg 0.069851 0.018530 3.770 0.000
L1.Wien -0.016043 0.034415 -0.466 0.641
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.129440 0.052193 2.480 0.013
L1.Burgenland -0.052249 0.034670 -1.507 0.132
L1.Kärnten -0.040127 0.018409 -2.180 0.029
L1.Niederösterreich 0.170345 0.072389 2.353 0.019
L1.Oberösterreich 0.140876 0.070228 2.006 0.045
L1.Salzburg 0.288159 0.037071 7.773 0.000
L1.Steiermark 0.032084 0.048372 0.663 0.507
L1.Tirol 0.161269 0.039155 4.119 0.000
L1.Vorarlberg 0.101219 0.033664 3.007 0.003
L1.Wien 0.070912 0.062524 1.134 0.257
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056204 0.041573 1.352 0.176
L1.Burgenland 0.040443 0.027615 1.465 0.143
L1.Kärnten 0.050264 0.014663 3.428 0.001
L1.Niederösterreich 0.221028 0.057659 3.833 0.000
L1.Oberösterreich 0.283837 0.055938 5.074 0.000
L1.Salzburg 0.045732 0.029528 1.549 0.121
L1.Steiermark -0.001618 0.038529 -0.042 0.967
L1.Tirol 0.147914 0.031187 4.743 0.000
L1.Vorarlberg 0.072565 0.026814 2.706 0.007
L1.Wien 0.084483 0.049801 1.696 0.090
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.179891 0.049798 3.612 0.000
L1.Burgenland -0.005578 0.033078 -0.169 0.866
L1.Kärnten -0.061418 0.017564 -3.497 0.000
L1.Niederösterreich -0.082269 0.069066 -1.191 0.234
L1.Oberösterreich 0.196423 0.067004 2.932 0.003
L1.Salzburg 0.056493 0.035370 1.597 0.110
L1.Steiermark 0.230123 0.046152 4.986 0.000
L1.Tirol 0.493971 0.037357 13.223 0.000
L1.Vorarlberg 0.047703 0.032119 1.485 0.137
L1.Wien -0.053120 0.059654 -0.890 0.373
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.165248 0.057176 2.890 0.004
L1.Burgenland -0.011323 0.037979 -0.298 0.766
L1.Kärnten 0.067229 0.020166 3.334 0.001
L1.Niederösterreich 0.206344 0.079299 2.602 0.009
L1.Oberösterreich -0.070074 0.076931 -0.911 0.362
L1.Salzburg 0.211350 0.040610 5.204 0.000
L1.Steiermark 0.115611 0.052990 2.182 0.029
L1.Tirol 0.071231 0.042892 1.661 0.097
L1.Vorarlberg 0.121989 0.036878 3.308 0.001
L1.Wien 0.123964 0.068492 1.810 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.360010 0.032978 10.917 0.000
L1.Burgenland 0.006004 0.021906 0.274 0.784
L1.Kärnten -0.023352 0.011631 -2.008 0.045
L1.Niederösterreich 0.215199 0.045738 4.705 0.000
L1.Oberösterreich 0.191976 0.044372 4.326 0.000
L1.Salzburg 0.045562 0.023423 1.945 0.052
L1.Steiermark -0.017467 0.030563 -0.571 0.568
L1.Tirol 0.105839 0.024739 4.278 0.000
L1.Vorarlberg 0.073244 0.021270 3.444 0.001
L1.Wien 0.044643 0.039505 1.130 0.258
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040404 0.148727 0.192212 0.157579 0.124197 0.112619 0.065819 0.222736
Kärnten 0.040404 1.000000 -0.003989 0.133678 0.041033 0.095819 0.431083 -0.052344 0.100296
Niederösterreich 0.148727 -0.003989 1.000000 0.336755 0.149767 0.299183 0.107934 0.182650 0.322581
Oberösterreich 0.192212 0.133678 0.336755 1.000000 0.227627 0.331484 0.173333 0.167684 0.264689
Salzburg 0.157579 0.041033 0.149767 0.227627 1.000000 0.147204 0.122525 0.147271 0.131585
Steiermark 0.124197 0.095819 0.299183 0.331484 0.147204 1.000000 0.151019 0.137818 0.078867
Tirol 0.112619 0.431083 0.107934 0.173333 0.122525 0.151019 1.000000 0.115012 0.152412
Vorarlberg 0.065819 -0.052344 0.182650 0.167684 0.147271 0.137818 0.115012 1.000000 0.006354
Wien 0.222736 0.100296 0.322581 0.264689 0.131585 0.078867 0.152412 0.006354 1.000000